package cn.org.eshow.service.impl;

import cn.org.eshow.bean.query.OrderStepQuery;
import cn.org.eshow.common.page.Page;
import cn.org.eshow.dao.OrderStepDao;
import cn.org.eshow.model.OrderStep;
import cn.org.eshow.model.ProductOrder;
import cn.org.eshow.service.OrderStepManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.jws.WebService;
import java.util.Date;
import java.util.List;

@WebService(serviceName = "OrderStepService", endpointInterface = "cn.org.eshow.service.OrderStepManager")
@Service
public class OrderStepManagerImpl extends GenericManagerImpl<OrderStep, Integer> implements OrderStepManager {

	@Autowired
	OrderStepDao orderStepDao;

	public OrderStepManagerImpl() {
	}

	@Autowired
	public OrderStepManagerImpl(OrderStepDao orderStepDao) {
		super(orderStepDao);
		this.orderStepDao = orderStepDao;
	}

	@Override
	public List<OrderStep> list(OrderStepQuery query) {
		return orderStepDao.list(query);
	}

	@Override
	public Page<OrderStep> search(OrderStepQuery query) {
		return orderStepDao.search(query);
	}

	@Override
	public OrderStep check(OrderStepQuery query) {
		List<OrderStep> list = orderStepDao.list(query);
		if (!list.isEmpty()) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public OrderStep save(String state, String content, ProductOrder productOrder) {
		OrderStep orderStep=new OrderStep();
		orderStep.setAddTime(new Date());
		orderStep.setState(state);
		orderStep.setContent(content);
		orderStep.setProductOrder(productOrder);
		orderStep.setUser(productOrder.getUser());
		return orderStepDao.save(orderStep);
	}

}